<template>
  <el-dialog v-dialogDrag :visible.sync="dialogVisible" title="停机信息" width="950px" @close="resetForm('ruleForm')">
    <button-group ref="buttonGroup" @cancel="dialogVisible = false" />
    <div class="formTopFont">停机记录单</div>
    <el-row>
      <div class="detailCont detailDialogFont twoDetailStyle">
        <h1>基本信息</h1>
        <ul>
          <li>
            <b>设备</b>
            <span>{{ obj.equipName}}{{ obj.equipCode ? '【' + obj.equipCode + '】' : '' }}</span>
          </li>
          <li>
            <b>设备分类</b>
            <span>{{ obj.equipType }}</span>
          </li>
          <li>
            <b>停机时间</b>
            <span>{{ obj.beginDt }}</span>
          </li>
          <li>
            <b>恢复时间</b>
            <span>{{ obj.endDt }}</span>
          </li>
          <li>
            <b>停机时长</b>
            <span>{{ obj.estimatedDowntime }}</span>
          </li>
          <li>
            <b>停机类型</b>
            <span>{{obj.stopType == '1' ? '维修': '保养'}}</span>
          </li>
          <li>
            <b>维保分类名称</b>
            <span>{{ obj.name }}</span>
          </li>
          <li>
            <b>维保分类编码</b>
            <span>{{ obj.code }}</span>
          </li>
        </ul>
      </div>
      <h1 class="titleH1">转入知识库信息</h1>
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="110px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="处理人" prop="handleBy">
              <el-select v-model="ruleForm.handleBy" style="width: 100%">
                <el-option v-for="item in userAllList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="处理时间" prop="handleDt">
              <el-date-picker v-model="ruleForm.handleDt" :clearable="false" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="处理方案" prop="treatmentScheme">
            <el-input v-model="ruleForm.treatmentScheme" maxlength="200" type="textarea" rows="3" show-word-limit />
          </el-form-item>
        </el-row>
      </el-form>
      <p style="text-align:right;">
        <el-button type="primary" icon="el-icon-check" @click="submitForm('ruleForm')">转入知识库</el-button>
      </p>
    </el-row>
  </el-dialog>
</template>
<script>
export default {
  props: {
    userAllList: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      title: '',
      ruleForm: {
        handleBy: '',
        handleDt: '',
        treatmentScheme: '',
        id: ''
      },
      rules: {
        handleBy: [
          { required: true, message: '请选择处理人！', trigger: 'change' }
        ],
        handleDt: [
          { required: true, message: '请选择处理日期！', trigger: 'change' }
        ]
      },
      dialogVisible: false,
      obj: {}
    }
  },
  watch: {},
  mounted() {},
  methods: {
    /**
     * @description: 新增编辑
     * @param {*} row
     * @return {*}
     */
    async showDialog(row) {
      this.obj = row
      this.dialogVisible = true
      this.ruleForm.id = row.id
    },
    /**
     * @description: 表单提交
     * @param {*} formName
     * @return {*}
     */
    submitForm(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          const res = await this.$axios.post(
            '/equip/shutDown/saveKnowledge',
            this.ruleForm
          )
          if (res?.data.code === 200) {
            this.$notify.success('提交成功！')
            this.dialogVisible = false
            this.$emit('getTableInfo')
          } else {
            this.$notify.error(res.data.msg)
          }
        }
      })
    },
    /**
     * @description: 重置表单
     * @param {*} formName
     * @return {*}
     */
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.ruleForm = {
        handleBy: '',
        handleDt: '',
        treatmentScheme: '',
        id: ''
      }
    }
  }
}
</script>
<style lang='scss' scoped>
.dialogBtn {
  text-align: right;
}
</style>
